package cn.itcast.erp.service.impl;

import cn.itcast.erp.dao.mapper.*;
import cn.itcast.erp.entity.Emp;
import cn.itcast.erp.entity.Role;
import cn.itcast.erp.entity.Storealert;
import cn.itcast.erp.entity.utils.SendMail;
import cn.itcast.erp.service.RoleService;
import cn.itcast.erp.service.StorealertService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 库存预警发送邮件
 */

@Service("storealertService")
public class StorealertServiceImpl implements StorealertService {


    @Resource
    private SendMail sendMail;
    @Resource
    private CStoreDetailMapper cStoreDetailMapper;

    @Override
    public String sendStorealerMail() {

        Storealert storealert = new Storealert();
        List<Storealert> slist = this.cStoreDetailMapper.findStorealerts(storealert);
        int sum = slist.size();

        if (slist.size() > 0) {
            String sendaddress = "zcy11050607@163.com";
            String password = "zcy0607";
            String sendName = "库存预警";
            String acceptName = "a1843693653@126.com";

            sendMail.sendMail(sendaddress, password, sendName, acceptName);
            sendMail.mailClass("163");
            String storealerts = "";
            storealerts = "有" + sum + "种商品库存不够,请及时补全,详情请登录蓝云管理系统查看";
            String s = sendMail.mailTest(storealerts);
            return s;
        } else {
            return "目前库存充足,不需要发邮件";
        }
    }


}
